package main

import (
	"context"
	"grpc-go-demo/echo"
	"io"
	"log"

	"google.golang.org/grpc"
)

func main() {
	connect, err := grpc.Dial("localhost:8080", grpc.WithInsecure())
	if err != nil {
		log.Fatalln(err.Error())
	}
	defer connect.Close()

	client := echo.NewEchoClient(connect)

	stream, err := client.ServerStreamEcho(context.Background(), &echo.EchoRequest{Message: "shangchao"})
	if err != nil {
		log.Println(err.Error())
	}
	for {
		resp, err := stream.Recv()
		if err == io.EOF {
			log.Println("receive closed")
			break
		}
		if err != nil {
			log.Println("receive error")
			continue
		}
		log.Println("received:", resp.GetMessage())
	}
}
